<?php
//----------------------------------------------------------------------------//
// File              : V_QuyHoachAdd										  //
// Modification       :														  //
//----------------------------------------------------------------------------//
// Date(yyyy.mm.dd)   Developer                       Action				  //
//----------------------------------------------------------------------------//
// 2007.03.05         Tran Thanh                     Created				  //
//----------------------------------------------------------------------------//
?>
<script language=javascript>
function doUpload() 
{
	if (document.frm.tieu_de.value=="") {
		alert("Tiêu đề không được rỗng");
		document.frm.tieu_de.focus();
		return false;
	}
	
	var filename = document.frm.userfile.value;
	var dotpos;
	filename = filename.substring(filename.lastIndexOf("\\")+1,filename.length);
	dotpos=filename.lastIndexOf('.');
	ext=filename.substr(dotpos+1,3);
	ext=ext.toLowerCase();
	fname=filename.substr(0,dotpos);
	if (document.frm.userfile.value!="") {
		if(dotpos==-1||dotpos==0){
			alert("Xin lỗi bạn click vào browser để chọn đúng đường dẫn.");
			return false;
		}
	}

	if (ext!="")
		if ((ext!="gif") && (ext!="jpg") && (ext!="png")  && (ext!="bmp")){
			alert("We only accept file format of GIF, JPG, PNG. Please try again.");
			return false;
		}

	return true;
}
function Focus(){
	document.frm.tieu_de.focus();
}
function showImage(urlimage)
{
	
	if(document.frm.userfile.value!=""){
		choseImage(document.frm.userfile.value);
		
	}else{
		choseImage(urlimage);
	}
}


function btnClearImgOnclick(){
	if (document.frm.userfile.value != ""){
		if (confirm("Bạn có muốn xóa ảnh không?")){
			document.frm.previewField.src = "";
			//document.f.chu_thich_anh.value = "";
			document.getElementById("fn").value='';
			document.getElementById("fileIDSpan").innerHTML=
					"<input name=\"userfile\" type=\"file\" id=\"fn\"  size=\"100\" value=\"\" onChange=\" showImage();\"/>";
		}
	}
}

</script>

<?php
include("../fckeditor/fckeditor.php") ;
function V_TintucAdd(&$arrayData,$mode)
{
	global $arrayError;
	$ulr = "?".MODUL."=tintuc&".ACTION."=".$mode;

	$strButtonLabel ="Ghi lại";
	$strLabel ="Sửa thông tin sự kiện";
	if ($mode == "Add"){
		$strButtonLabel ="Thêm mới";	
		$strLabel ="Thêm mới thông tin sự kiện";
	}	
	$strHienThi1 = 'checked="checked"';
	$strHienThi0 = '';
	if($arrayData["hien_thi"]=="0" && $mode!="Add"){
		$strHienThi1 = '';
		$strHienThi0 = 'checked="checked"';
	}
//	htmlentities(
?>
<?= CM_showError() ?>
<?php
	$tom_tat=$arrayData['tom_tat'];
	$noi_dung=$arrayData['noi_dung'];
	$anh=$arrayData['anh'];
	$chu_thich_anh=$arrayData['chu_thich_anh'];
	$thu_tu=$arrayData['thu_tu'];
	$url_image=DIR_UPLOADFILE_IMAGES.$anh;
?>
<style type="text/css">
<!--
.style1 {color: #000099}
.style2 {
	color: #000000;
	font-weight: bold;
}
-->
</style>
<body onLoad="Focus();">
<table width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FF9900" bordercolordark="white">
<form enctype="multipart/form-data" action="<?=$ulr?>" method="post" name="frm" id="frm" onSubmit="return doUpload();">
	<input type="hidden" name="id" value="<?=htmlspecialchars($arrayData["id"])?>" />
	<input type="hidden" name="cat_id1" value="<?=$cat_id?>" />
	<input type="hidden" name="curPg" value="<?=CM_getParameter("curPg");?>" />
	<input type="hidden" name="section_id_hidden" value="<?=htmlspecialchars($arrayData["section_id"])?>" />
	<input type=hidden name="cat_id" value="<?=CM_getParameter("cat_id")?>"> 
        <tr>
          <td colspan="2" bgcolor="#FFE59F"  class=bk12-140><div align="center"><font size="3"><b><?=$strLabel?></b></font></div></td>
        </tr>
        <tr>
          <td  bgcolor="#FFE59F"  ><span class="style1"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Ti&ecirc;u &#273;&ecirc;&#768;:</font></span><span style="color:#FF0000;">*</span></td>
          <td >
          <input name="tieu_de" type="text" id="tieu_de" value="<?=htmlspecialchars($arrayData["tieu_de"])?>" size="100" maxlength="100" />
         </td>
		  
        </tr>
        <tr>
          <td  bgcolor="#FFE59F"  ><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1"> Nguồn tin:</span></font></td>
          <td >
				<input name="nguon_tin" type="text" id="nguon_tin" value="<?=htmlspecialchars($arrayData["nguon_tin"])?>" size="100" maxlength="100" />
          </td>
        </tr>
        <tr>
          <td  bgcolor="#FFE59F"  ><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">Hi&#7875;n th&#7883;:</span></font></td>
          <td ><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">
         
          </span>
              <label>
              <input name="hien_thi" type="radio" value="1" <?=$strHienThi1?> />
C&oacute;</label>
              <label>
              <input name="hien_thi" type="radio" value="0" <?=$strHienThi0 ?> />
Kh&ocirc;ng</label>
          </font> </td>
        </tr>
		<tr>
		  <td  bgcolor="#FFE59F"  ><span class="style1"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Thứ tự sắp xếp:</font></span></td>
		  <td >
		  <input name="thu_tu" type="text" id="thu_tu" value="<?=htmlspecialchars($thu_tu)?>" size="3" maxlength="254" />
		 </td>
		</tr>
        <tr>
          <td  bgcolor="#FFE59F"  ><span class="style1"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> Ảnh:</font></span></td>
          <td ><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">Tóm tắt:</span></font></td>
        </tr>
        <tr>
          <td width="205"><table cellSpacing=0 cellPadding=3 border=0 align=left>
					<tr>
						<td>
							<img name='previewField' height=150 width=150 id='previewField' border=0 
							src="<?=DIR_UPLOADFILE_IMAGES.$anh?>"  onLoad="showImage('<?=$url_image?>');" align=left >
						</td>
					</tr>
				</table></td>
          <td width="877">
          <textarea name="tom_tat" cols="77" rows="9" id="tom_tat"><?=htmlspecialchars($tom_tat)?></textarea>
	</td>
        </tr>
		<tr>
          <td  bgcolor="#FFE59F"  ><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">Ch&uacute; thích ảnh: </span>&nbsp;</font> </td>
          <td ><input name="chu_thich_anh" type="text" id="chu_thich_anh" value="<?=htmlspecialchars($chu_thich_anh)?>" size="100" maxlength="245" /></td>
    </tr>
		<tr>
          <td  bgcolor="#FFE59F"  >
		  	  <font size="2" face="Verdana, Arial, Helvetica, sans-serif">
			  		<span class="style1">Tên ảnh:</span>
              </font>
		 </td>
		 <td ><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
		  <?
		  	if($mode=="Edit"){
		  ?>
		  		<br><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <?=htmlspecialchars($arrayData["anh"])?>
							</font>
		 <?
		 	}else{}
		 ?>
		 	<span id="fileIDSpan">
            <input name="userfile" type="file" id="fn"  size="80" value="<?=htmlspecialchars($arrayData["anh"])?>" onChange=" showImage();"/>
          </span></font>
		  </td>
     
    </tr>
	<tr>
		<td class="style1" bgcolor="#FFE59F">
			<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Nội dung: </font>
		</td>
		<td>
         <?php
			// Automatically calculates the editor base path based on the _samples directory.
			// This is usefull only for these samples. A real application should use something like this:
			// $oFCKeditor->BasePath = '/fckeditor/' ;    // '/fckeditor/' is the default value.
			//$_SERVER : is an array containing information such as headers, paths, and script locations.
			//           The entries in this array are created by the web server.
			//           This is a automatic global, variable. This simply means that it is available in all scopes throughout a script.
			//           You don't need to do a global $_SERVER; to access it within functions or methods,
			//'PHP_SELF' : The filename of the currently executing script, relative to the document root.
			//             For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar
			//             would be /test.php/foo.bar. The __FILE__  constant contains the full path and filename of the current (i.e. included) file.
			// Lay ve duong dan chinh cua server.
			$sBasePath = $_SERVER['PHP_SELF'] ;
			// Lay ve thu muc goc cho den _sample.
			$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "run" ) ) ;
			
			$sBasePath = $sBasePath."fckeditor/";
			$oFCKeditor = new FCKeditor('noi_dung') ;
			$oFCKeditor->BasePath    = $sBasePath ;
			$oFCKeditor->Width        = '100%' ;
			$oFCKeditor->Height        = '400' ;
			$oFCKeditor->Value       = $noi_dung;
			$oFCKeditor->Create() ;
			?>
		 </td>
	</tr>
	
				<script language = 'JavaScript' >
				function backToList(){
					location = '<? echo "?".MODUL."=tintuc&".ACTION."=List&curPg=".CM_getParameter("curPg")."";?>';
					return;
				}
				</script>
				<tr>
					<td colspan="2" align="center">
						<input name="Reset" type="reset" value="Nhập lại" />
						<input name="Submit" type="submit" value="<?=$strButtonLabel?>" />
						<!--<input type="button" name="back" value="Trở lại "
						onClick="javascript: return backToList();"> -->
						<input type="button" name="back" value=" Trở lại " onClick="history.go(-1)">
					</td>
				</tr>
			</tbody>
<input type=hidden name="modul" value="<?=CM_getParameter("modul")?>"> 
<input type=hidden name="<?=ACTION2?>" value="<?=CM_getParameter(ACTION2)?>"> 
<input type=hidden name="textfield" value="<?=CM_getParameter("textfield")?>"> 
</form>
</table>
</body>
<?php
}
?>
